package myzzyl.controller;



import cn.hutool.db.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import myzzyl.domain.dto.NursingProjectDto;
import myzzyl.domain.dto.RoomDto;
import myzzyl.domain.pojo.NursingProject;
import myzzyl.domain.vo.NursingProjectVo;
import myzzyl.domain.vo.RoomVo;
import myzzyl.response.BaseResponse;
import myzzyl.response.PageResponse;
import myzzyl.service.NursingProjectService;
import myzzyl.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Tag(name = "护理项目相关")
@Slf4j
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页获取所有护理项目
     */
    @GetMapping
    public BaseResponse<PageResponse<NursingProjectVo>> getAll(
            @RequestParam(name = "name", required = false) String name,
            @RequestParam(name = "status", required = false) Integer status,
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        log.info("分页获取所有护理项目:{}, {}, {}, {}", name, status, pageNum, pageSize);
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.getAll(name, status, pageNum, pageSize);
        return BaseResponse.success(pageResponse);
    }

    /**
     * 获取所有护理项目
     */
    @GetMapping("/all")
    public BaseResponse<List<NursingProjectVo>> listAll() {
        log.info("获取所有护理项目");
        return BaseResponse.success(nursingProjectService.listAll());
    }


    /**
     * 获取护理项目详情
     */
    @GetMapping("/{id}")
    public BaseResponse<NursingProjectVo> getInfo(@PathVariable Long id) {
        log.info("获取护理项目详情:{}", id);
        return BaseResponse.success(nursingProjectService.getInfo(id));
    }


    /**
     * 新增护理项目
     */
    @PostMapping
    public BaseResponse<Boolean> add(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("新增护理项目:{}", nursingProjectDto);
        return nursingProjectService.add(nursingProjectDto) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }


    /**
     * 编辑护理项目
     */
    @PutMapping
    public BaseResponse<Boolean> edit(@RequestBody NursingProjectDto nursingProjectDto) {
        log.info("编辑护理项目:{}", nursingProjectDto);
        return nursingProjectService.edit(nursingProjectDto) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

    /**
     * 删除护理项目
     */
    @DeleteMapping("/{id}")
    public BaseResponse<Boolean> remove(@PathVariable Long id) {
        log.info("删除护理项目:{}", id);
        return nursingProjectService.deleteNursingProjectById(id) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

    /**
     * 启用或禁用护理项目
     */
    @PutMapping("/{id}/status/{status}")
    public BaseResponse<Boolean> enableOrDisableNursingProject(@PathVariable("id") Long id,
                                                               @PathVariable("status") Integer status) {
        log.info("启用或禁用护理项目:{}, {}", id, status);
        return nursingProjectService.enableOrDisableNursingProject(id, status) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

}
